home *** CD-ROM | disk | FTP | other *** search
- #ifndef __WINDOWMANAGER__
- #define __WINDOWMANAGER__
- #pragma once
-
- #include "Module.h"
- #include "EventFilter.h"
- #include <Windows.h>
-
- class WindowManager;
-
- const WindowRef kBeforeFirstWindow = (WindowRef) -1;
- const short kScreenEdgeSlop = 4;
- const short kSpaceForFinderIcons = 64;
- const short kMinimumTitleBarHeight = 21;
- const short kMinimumWindowSize = 32;
-
- enum
- {
- kScrollbarWidth = 16, // width of a standard Macintosh scrollbar
- kScrollbarTweak = 2 // left edge = rightedge - kScrollbarWidth + kScrollbarTweak
- };
-
-
- enum WindowLayer
- {
- kAnyWindowLayer = -1,
- kNormalWindowLayer = 0,
- kFloatingWindowLayer,
- // kModalWindowLayer,
- kNumWindowLayers
- };
-
-
- class WindowManager : public TModule, public EventFilter
- {
- DeclareClass2Base(WindowManager, TModule, EventFilter);
-
- protected:
- RgnHandle fScratchRgn;
- bool fHasColorQuickdraw;
- bool fHasDisplayManager;
-
- public:
- WindowManager();
- virtual ~WindowManager();
-
- virtual bool Validate(void); // Check against system, possibly re-order
- virtual void Initialize(void);
- virtual void Finalize(void);
- virtual bool Initialized(void);
- virtual bool InitializeCalled(void); // Return true if you have been initialized
-
- virtual bool FilterEvent(ToolboxEvent& evt);
-
- //
- // Window manager replacement functions - call as needed to support floating windows, etc.
- //
- virtual WindowRef GetNewWindow(short windowID, WindowRef behind, WindowLayer layer = kNormalWindowLayer);
- virtual WindowRef NewWindow(const Rect &boundsRect, ConstStr255Param title, bool visible, short theProc, WindowRef behind, bool goAwayFlag, long refCon, WindowLayer layer = kNormalWindowLayer);
- virtual void DisposeWindow(WindowRef aWindow);
-
- virtual void SelectWindow(WindowRef aWindow);
- virtual void UpdateWindow(WindowRef aWindow);
- virtual void ActivateWindow(WindowRef aWindow);
- virtual void DeactivateWindow(WindowRef aWindow);
- virtual void ShowWindow(WindowRef aWindow);
- virtual void HideWindow(WindowRef aWindow);
- virtual void CloseWindow(WindowRef aWindow);
-
- virtual void SuspendApplication();
- virtual void ResumeApplication();
- virtual void BeginModalDialog();
- virtual void EndModalDialog();
-
- virtual WindowLayer GetWindowLayer(WindowRef aWindow);
- virtual WindowRef FrontWindow(WindowLayer layer = kNormalWindowLayer);
- virtual WindowRef BackWindow(WindowLayer layer = kNormalWindowLayer);
- virtual WindowRef GetNthWindow(long index, WindowLayer layer = kNormalWindowLayer);
- virtual WindowRef GetNamedWindow(ConstStr255Param winName, WindowLayer layer = kNormalWindowLayer);
- virtual long GetWindowIndex(WindowRef aWindow, WindowLayer layer = kNormalWindowLayer);
-
- virtual bool IsWindowVisible(WindowRef aWindow);
- virtual bool IsWindowHilited(WindowRef aWindow);
- virtual bool IsWindowModal(WindowRef aWindow);
- virtual bool IsWindowFloating(WindowRef aWindow);
- virtual bool IsDialogWindow(WindowRef aWindow);
-
- virtual bool PointInStructureRgn(WindowRef aWindow, Point pt);
- virtual bool PointInContentRgn(WindowRef aWindow, Point pt);
- virtual Rect GetWindowStructureBounds(WindowRef aWindow);
- virtual Rect GetWindowContentBounds(WindowRef aWindow);
-
- virtual void SetWindowBounds(WindowRef aWindow, Rect newBounds);
- virtual void DragWindow(WindowRef aWindow, Point startPoint);
- virtual void NudgeWindow(WindowRef aWindow, short horizontalDistance, short verticalDistance);
- virtual void GrowWindow(WindowRef aWindow, Point startPoint, const Rect* resizeLimits = nil);
- virtual void ZoomWindow(WindowRef aWindow, short zoomState, const Rect* perfectWindowRect = nil);
-
- virtual void DrawWindowGrowIcon(WindowRef aWindow);
-
- protected:
- virtual void HiliteShowHideFloatingWindows(bool active, bool hide);
- };
-
- class WithWindowManagerPort
- {
- private:
- GrafPtr fSavedPort;
-
- public:
- WithWindowManagerPort() { GrafPtr wmPort; ::GetPort(&fSavedPort); ::GetWMgrPort(&wmPort); ::SetPort(wmPort); }
- ~WithWindowManagerPort() { ::SetPort(fSavedPort); }
- };
-
-
- class WithWindowPort
- {
- private:
- GrafPtr fSavedPort;
-
- public:
- WithWindowPort(WindowRef aWindow) { ::GetPort(&fSavedPort); ::SetPortWindowPort(aWindow); }
- ~WithWindowPort() { ::SetPort(fSavedPort); }
- };
-
-
- class WindowListIterator
- {
- private:
- WindowRef fCurWindow;
-
- public:
- WindowListIterator() { fCurWindow = ::FrontWindow(); }
- ~WindowListIterator() { }
-
- bool More() { return ::GetNextWindow(fCurWindow) != nil; }
- WindowRef First() { return fCurWindow = ::FrontWindow(); }
- WindowRef Next() { return fCurWindow ? fCurWindow = ::GetNextWindow(fCurWindow) : nil; }
-
- #if 0
- {
- Assert(layer == kNormalWindow);
- Assert(index > 0);
-
- WindowRef win = FrontNonFloatingWindow();
-
- while (win != nil && --index >= 0)
- {
- if (index == 0)
- {
- return GetWindowObject(win);
- }
-
- win = GetNextWindow(win);
- }
-
- return nil;
- }
- #endif
-
- };
-
-
- #if STRICT_WINDOWS && defined(__cplusplus)
-
- // I kind of like to be able to see what's going on in the debugger
- // (note that this is just as secure as what apple's doing)
-
- struct OpaqueWindowRef : private CGrafPort
- {
- private:
- // CGrafPort port;
- short windowKind;
- bool visible;
- bool hilited;
- bool goAwayFlag;
- bool spareFlag;
- RgnHandle strucRgn;
- RgnHandle contRgn;
- RgnHandle updateRgn;
- Handle windowDefProc;
- Handle dataHandle;
- StringHandle titleHandle;
- short titleWidth;
- ControlRef controlList;
- OpaqueWindowRef* nextWindow;
- PicHandle windowPic;
- long refCon;
- };
-
- #endif // STRICT_WINDOWS && defined(__cplusplus)
-
-
- #endif // __WINDOWMANAGER__
-
-